#ifndef __RED_FILE_OBJECT_H__
#define __RED_FILE_OBJECT_H__

#include <stdio.h>
#include "redobject.h"

typedef struct _RedFileObject
{
	RedObject_HEAD

	FILE		*f_fp;
	char		 f_std;
	RedObject	*f_mode;
	RedObject	*f_name;
	RedObject	*f_buffer;
} RedFileObject;

RED_EXPORT extern RedTypeObject RedType_File;

#define RedFile_Exact(o)		((o)->ob_type == &RedType_File)

#define RedFile_FP(o)			(((RedFileObject *)(o))->f_fp)
#define RedFile_Std(o)			(((RedFileObject *)(o))->f_std)
#define RedFile_Mode(o)			(((RedFileObject *)(o))->f_mode)
#define RedFile_Name(o)			(((RedFileObject *)(o))->f_name)
#define RedFile_Buffer(o)		(((RedFileObject *)(o))->f_buffer)

RED_EXPORT RedObject *RedFile_Wrap(const char *name, FILE *fp);
RED_EXPORT RedObject *RedFile_Open(const char *name, const char *mode);

RED_EXPORT RedObject *RedFile_Read(RedObject *self, int size);
RED_EXPORT RedObject *RedFile_ReadAll(RedObject *self);
RED_EXPORT RedObject *RedFile_ReadLine(RedObject *self);

RED_EXPORT int RedFile_Write(RedObject *self, RedObject *data);
RED_EXPORT int RedFile_WriteBuffer(RedObject *self, const char *data, int size);

RED_EXPORT int RedFile_Tell(RedObject *self);
RED_EXPORT char RedFile_Seek(RedObject *self, int pos, int whence);

RED_EXPORT char RedFile_Flush(RedObject *self);
RED_EXPORT char RedFile_Close(RedObject *self);

#endif /* __RED_FILE_OBJECT_H__ */
